package com.duan.laugh.email.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.duan.laugh.common.core.util.Query;
import com.duan.laugh.common.core.util.R;
import com.duan.laugh.email.api.pojo.entity.EmailSendLog;
import com.duan.laugh.email.service.IEmailSendLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 邮件发送日志 controller
 * </p>
 *
 * @author liutf
 * @since 2019-11-07
 */
@Api(tags = "邮件发送日志")
@RestController
@RequestMapping("/email-send-log")
public class EmailSendLogController {
    @Autowired
    private IEmailSendLogService emailSendLogService;

    /**
     * 新增邮件发送日志
     *
     * @param emailSendLog 实体
     * @return true/false
     */
    @PostMapping
    @ApiOperation("新增邮件发送日志")
    public R save(@RequestBody EmailSendLog emailSendLog) {
        return R.ok(emailSendLogService.save(emailSendLog));
    }

    /**
     * 根据id查看邮件发送日志
     *
     * @param id
     * @return EmailSendLog
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查看邮件发送日志")
    public R<EmailSendLog> getById(@PathVariable String id) {
        return R.ok(emailSendLogService.getById(id));
    }

    /**
     * 分页查询邮件发送日志
     *
     * @param params 分页对象
     * @return 分页对象
     */
    @PostMapping("/page")
    @ApiOperation("分页查询邮件发送日志")
    public IPage<EmailSendLog> page(@RequestBody Map<String, Object> params) {
        return emailSendLogService.page(new Query<>(params));
    }

    /**
     * 根据id删除邮件发送日志
     *
     * @param id
     * @return true/false
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除邮件发送日志")
    public R removeById(@PathVariable String id) {
        return R.ok(emailSendLogService.removeById(id));
    }

    /**
     * 根据id修改邮件发送日志
     *
     * @param emailSendLog 实体
     * @return true/false
     */
    @PutMapping
    @ApiOperation("根据id修改邮件发送日志")
    public R updateById(@RequestBody EmailSendLog emailSendLog) {
        return R.ok(emailSendLogService.updateById(emailSendLog));
    }

}

